package iso3.pt.action;

import iso3.pt.model.Alumno;
import iso3.pt.model.Asignatura;
import iso3.pt.model.Evaluacion;
import iso3.pt.model.Unidad;
import iso3.pt.service.PtDaoService;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;


public class SubjectAction extends ActionSupport implements Preparable {
	private static final long serialVersionUID = 1L;
	private Alumno student;
	private Asignatura subject;
	private int subjectID;
	private int studentDNI;
	private String concept;
	private float mark;
	private List<Unidad> unitList;
	private List<Evaluacion> evaluationList;	

	public String execute() throws Exception {
		PtDaoService dao = new PtDaoService();
		subject = dao.getAsignatura(subjectID);
		student = dao.getAlumno(studentDNI);
		evaluationList = new ArrayList<Evaluacion>();
		
		for (Evaluacion eval: dao.getEvaluaciones(subjectID, studentDNI)) {
			evaluationList.add(eval);
		}
		
		return SUCCESS;
	}
	
	public String showSubjectsMarkList()
	{
		evaluationList = new ArrayList<Evaluacion>();
		
		for(Evaluacion eval: student.getListaEvaluaciones()) {
			subject = eval.getAsignatura();
        	evaluationList.add(eval);
		}
		return "showSubjectMarkList";
	}

	public String showSubjectUnits() {
		PtDaoService dao = new PtDaoService();
		unitList = new ArrayList<Unidad>(); 
		for (Unidad unit : dao.getUnidades(subjectID)) {
			unitList.add(unit);
		}
		return "showUnitList";
	}
	
	public String showLecturerSubjectUnits() {
		PtDaoService dao = new PtDaoService();
		unitList = new ArrayList<Unidad>(); 
		for (Unidad unit : dao.getUnidades(subjectID)) {
			unitList.add(unit);
		}
		return "showLecturerUnitList";
	}
	
	public String cancelSubjectListing() {
		return "backSubjectStudents";
	}
	
	public String cancelLecturerSubjectListing() {
		return "backSubjectLecturers";
	}
	
	@Override
	public void prepare() throws Exception {
		PtDaoService dao = new PtDaoService();
		student = dao.getAlumno(studentDNI);
		subject = dao.getAsignatura(subjectID);
	}

	public Alumno getStudent() {
		return student;
	}

	public void setStudent(Alumno student) {
		this.student = student;
	}

	public Asignatura getSubject() {
		return subject;
	}

	public void setSubject(Asignatura subject) {
		this.subject = subject;
	}

	public int getSubjectID() {
		return subjectID;
	}

	public void setSubjectID(int subjectID) {
		this.subjectID = subjectID;
	}

	public String getConcept() {
		return concept;
	}

	public void setConcept(String concept) {
		this.concept = concept;
	}

	public float getMark() {
		return mark;
	}

	public void setMark(float mark) {
		this.mark = mark;
	}

	public List<Unidad> getUnitList() {
		return unitList;
	}

	public void setUnitList(List<Unidad> unitList) {
		this.unitList = unitList;
	}
	
	public int getStudentDNI() {
		return studentDNI;
	}

	public void setStudentDNI(int studentDNI) {
		this.studentDNI = studentDNI;
	}
	
	public List<Evaluacion> getEvaluationList() {
		return evaluationList;
	}

	public void setEvaluationList(List<Evaluacion> evaluationList) {
		this.evaluationList = evaluationList;
	}
}
